{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "87442\n"
     ]
    }
   ],
   "source": [
    "import csv\n",
    "import numpy as np\n",
    "filename = 'D:\\\\xzr\\\\pycharm\\\\数据科学编程\\\\gaze.csv'\n",
    "data = []\n",
    "with open(filename) as csvfile:\n",
    "    csv_reader = csv.reader(csvfile)\n",
    "    for row in csv_reader:\n",
    "        data.append(row)\n",
    "    # ex1\n",
    "    list1 = []\n",
    "    for row1 in data:\n",
    "        try:\n",
    "            float1 = float(row1[2])\n",
    "        except:\n",
    "            continue\n",
    "        if float1 >= 0.9:\n",
    "            list1.append(row1)\n",
    "\n",
    "    print(len(list1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "120036\n"
     ]
    }
   ],
   "source": [
    "# ex2\n",
    "x_list = []\n",
    "y_list = []\n",
    "for row2 in data:\n",
    "    try:\n",
    "        float1 = float(row2[3])\n",
    "        float2 = float(row2[4])\n",
    "    except:\n",
    "        continue\n",
    "    x_list.append(float1)\n",
    "    y_list.append(float2)\n",
    "\n",
    "mean1 = np.mean(x_list)\n",
    "mean2 = np.mean(y_list)\n",
    "sigma1 = np.std(x_list, ddof=1)\n",
    "sigma2 = np.std(y_list, ddof=1)\n",
    "list2 = []\n",
    "for row3 in data:\n",
    "    try:\n",
    "        float1 = float(row3[3])\n",
    "        float2 = float(row3[4])\n",
    "    except:\n",
    "        continue\n",
    "    if mean1 - 3 * sigma1 < float1 < mean1 + 3 * sigma1 and mean2 - 3 * sigma2 < float2 < mean2 + 3 * sigma2:\n",
    "        list2.append(row)\n",
    "print(len(list2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1970-01-02 08:29:10\n"
     ]
    }
   ],
   "source": [
    "# ex3\n",
    "data1 = data\n",
    "for row4 in data1:\n",
    "    try:\n",
    "        timearray = time.localtime(float(row4[0]))\n",
    "    except:\n",
    "        continue\n",
    "    row4[0] = time.strftime(\"%Y-%m-%dT%H:%M:%S.225707+0000\", timearray)\n",
    "print(data1[1][0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "427.62610766083765\n"
     ]
    }
   ],
   "source": [
    "# ex4\n",
    "filename = 'D:\\\\xzr\\\\pycharm\\\\数据科学编程\\\\gaze.csv'\n",
    "data = []\n",
    "with open(filename) as csvfile:\n",
    "    csv_reader = csv.reader(csvfile)\n",
    "    for row in csv_reader:\n",
    "        data.append(row)\n",
    "time = []\n",
    "for row5 in data:\n",
    "    time.append(row5[0])\n",
    "s_time = float(time[1])\n",
    "e_time = float(time[-1])\n",
    "timej = e_time - s_time\n",
    "rate = (len(time) - 1) / timej\n",
    "print(rate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                  world_index  confidence  norm_pos_x  \\\n",
      "gaze_timestamp                                                          \n",
      "1970-01-02 00:29:10.770000+00:00          0.0    0.681690    0.437387   \n",
      "1970-01-02 00:29:10.780000+00:00          1.0    0.584288    0.437978   \n",
      "1970-01-02 00:29:10.790000+00:00          1.0    0.679988    0.494694   \n",
      "1970-01-02 00:29:10.800000+00:00          1.0    0.810370    0.494951   \n",
      "1970-01-02 00:29:10.810000+00:00          2.0    0.811268    0.494067   \n",
      "1970-01-02 00:29:10.820000+00:00          2.0    0.893564    0.493605   \n",
      "1970-01-02 00:29:10.830000+00:00          2.0    0.845289    0.493316   \n",
      "1970-01-02 00:29:10.840000+00:00          2.5    0.841835    0.492696   \n",
      "1970-01-02 00:29:10.850000+00:00          3.0    0.813601    0.492874   \n",
      "1970-01-02 00:29:10.860000+00:00          3.0    0.893743    0.492674   \n",
      "1970-01-02 00:29:10.870000+00:00          3.5    0.862389    0.492139   \n",
      "1970-01-02 00:29:10.880000+00:00          4.0    0.892706    0.492170   \n",
      "1970-01-02 00:29:10.890000+00:00          4.0    0.863562    0.491619   \n",
      "1970-01-02 00:29:10.900000+00:00          4.0    0.850346    0.491440   \n",
      "1970-01-02 00:29:10.910000+00:00          5.0    0.878314    0.491522   \n",
      "1970-01-02 00:29:10.920000+00:00          5.0    0.864336    0.491490   \n",
      "1970-01-02 00:29:10.930000+00:00          5.0    0.998242    0.491106   \n",
      "1970-01-02 00:29:10.940000+00:00          5.6    0.822405    0.491349   \n",
      "1970-01-02 00:29:10.950000+00:00          6.0    0.837220    0.491234   \n",
      "1970-01-02 00:29:10.960000+00:00          6.0    0.860573    0.490922   \n",
      "\n",
      "                                  norm_pos_y  gaze_point_3d_x  \\\n",
      "gaze_timestamp                                                  \n",
      "1970-01-02 00:29:10.770000+00:00    0.291906       -54.359308   \n",
      "1970-01-02 00:29:10.780000+00:00    0.307110       -42.813406   \n",
      "1970-01-02 00:29:10.790000+00:00    0.404853         1.979829   \n",
      "1970-01-02 00:29:10.800000+00:00    0.404822         1.859581   \n",
      "1970-01-02 00:29:10.810000+00:00    0.401053         2.204797   \n",
      "1970-01-02 00:29:10.820000+00:00    0.399335         2.409602   \n",
      "1970-01-02 00:29:10.830000+00:00    0.398559         2.512630   \n",
      "1970-01-02 00:29:10.840000+00:00    0.398804         2.767211   \n",
      "1970-01-02 00:29:10.850000+00:00    0.398257         2.711425   \n",
      "1970-01-02 00:29:10.860000+00:00    0.398524         2.798286   \n",
      "1970-01-02 00:29:10.870000+00:00    0.398724         3.005405   \n",
      "1970-01-02 00:29:10.880000+00:00    0.398582         3.002544   \n",
      "1970-01-02 00:29:10.890000+00:00    0.398328         3.227031   \n",
      "1970-01-02 00:29:10.900000+00:00    0.398221         3.300165   \n",
      "1970-01-02 00:29:10.910000+00:00    0.397330         3.278969   \n",
      "1970-01-02 00:29:10.920000+00:00    0.396538         3.308013   \n",
      "1970-01-02 00:29:10.930000+00:00    0.396239         3.462726   \n",
      "1970-01-02 00:29:10.940000+00:00    0.396675         3.365049   \n",
      "1970-01-02 00:29:10.950000+00:00    0.397143         3.410404   \n",
      "1970-01-02 00:29:10.960000+00:00    0.397230         3.540623   \n",
      "\n",
      "                                  gaze_point_3d_y  gaze_point_3d_z  \\\n",
      "gaze_timestamp                                                       \n",
      "1970-01-02 00:29:10.770000+00:00       103.262224       694.806989   \n",
      "1970-01-02 00:29:10.780000+00:00        41.035419        10.103229   \n",
      "1970-01-02 00:29:10.790000+00:00       -20.040517      -292.334754   \n",
      "1970-01-02 00:29:10.800000+00:00       -19.717564      -287.721641   \n",
      "1970-01-02 00:29:10.810000+00:00       -20.676414      -290.218427   \n",
      "1970-01-02 00:29:10.820000+00:00       -21.335674      -294.369777   \n",
      "1970-01-02 00:29:10.830000+00:00       -21.451642      -293.704395   \n",
      "1970-01-02 00:29:10.840000+00:00       -21.566487      -295.993985   \n",
      "1970-01-02 00:29:10.850000+00:00       -21.777256      -297.274745   \n",
      "1970-01-02 00:29:10.860000+00:00       -21.804480      -298.433361   \n",
      "1970-01-02 00:29:10.870000+00:00       -21.779999      -298.687614   \n",
      "1970-01-02 00:29:10.880000+00:00       -21.876653      -299.589471   \n",
      "1970-01-02 00:29:10.890000+00:00       -22.022033      -300.826326   \n",
      "1970-01-02 00:29:10.900000+00:00       -22.075103      -301.234553   \n",
      "1970-01-02 00:29:10.910000+00:00       -22.336895      -302.166428   \n",
      "1970-01-02 00:29:10.920000+00:00       -22.621279      -303.673027   \n",
      "1970-01-02 00:29:10.930000+00:00       -22.723509      -304.165507   \n",
      "1970-01-02 00:29:10.940000+00:00       -22.609107      -303.908032   \n",
      "1970-01-02 00:29:10.950000+00:00       -22.507586      -303.923452   \n",
      "1970-01-02 00:29:10.960000+00:00       -22.548167      -304.725183   \n",
      "\n",
      "                                  eye_center0_3d_x  eye_center0_3d_y  \\\n",
      "gaze_timestamp                                                         \n",
      "1970-01-02 00:29:10.770000+00:00         -9.967464         14.998960   \n",
      "1970-01-02 00:29:10.780000+00:00          0.021691         14.999306   \n",
      "1970-01-02 00:29:10.790000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.800000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.810000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.820000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.830000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.840000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.850000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.860000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.870000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.880000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.890000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.900000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.910000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.920000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.930000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.940000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.950000+00:00         20.000000         15.000000   \n",
      "1970-01-02 00:29:10.960000+00:00         20.000000         15.000000   \n",
      "\n",
      "                                  eye_center0_3d_z  gaze_normal0_x  \\\n",
      "gaze_timestamp                                                       \n",
      "1970-01-02 00:29:10.770000+00:00        -20.037641       -0.061136   \n",
      "1970-01-02 00:29:10.780000+00:00        -20.025094       -0.014355   \n",
      "1970-01-02 00:29:10.790000+00:00        -20.000000        0.065145   \n",
      "1970-01-02 00:29:10.800000+00:00        -20.000000        0.066672   \n",
      "1970-01-02 00:29:10.810000+00:00        -20.000000        0.064772   \n",
      "1970-01-02 00:29:10.820000+00:00        -20.000000        0.063058   \n",
      "1970-01-02 00:29:10.830000+00:00        -20.000000        0.062845   \n",
      "1970-01-02 00:29:10.840000+00:00        -20.000000        0.061422   \n",
      "1970-01-02 00:29:10.850000+00:00        -20.000000        0.061335   \n",
      "1970-01-02 00:29:10.860000+00:00        -20.000000        0.060777   \n",
      "1970-01-02 00:29:10.870000+00:00        -20.000000        0.059995   \n",
      "1970-01-02 00:29:10.880000+00:00        -20.000000        0.059813   \n",
      "1970-01-02 00:29:10.890000+00:00        -20.000000        0.058765   \n",
      "1970-01-02 00:29:10.900000+00:00        -20.000000        0.058422   \n",
      "1970-01-02 00:29:10.910000+00:00        -20.000000        0.058302   \n",
      "1970-01-02 00:29:10.920000+00:00        -20.000000        0.057891   \n",
      "1970-01-02 00:29:10.930000+00:00        -20.000000        0.057256   \n",
      "1970-01-02 00:29:10.940000+00:00        -20.000000        0.057648   \n",
      "1970-01-02 00:29:10.950000+00:00        -20.000000        0.057488   \n",
      "1970-01-02 00:29:10.960000+00:00        -20.000000        0.056879   \n",
      "\n",
      "                                  gaze_normal0_y  gaze_normal0_z  \\\n",
      "gaze_timestamp                                                     \n",
      "1970-01-02 00:29:10.770000+00:00        0.121556        0.984479   \n",
      "1970-01-02 00:29:10.780000+00:00        0.095046        0.987478   \n",
      "1970-01-02 00:29:10.790000+00:00        0.027374        0.997500   \n",
      "1970-01-02 00:29:10.800000+00:00        0.024890        0.997463   \n",
      "1970-01-02 00:29:10.810000+00:00        0.024500        0.997599   \n",
      "1970-01-02 00:29:10.820000+00:00        0.025140        0.997693   \n",
      "1970-01-02 00:29:10.830000+00:00        0.027284        0.997650   \n",
      "1970-01-02 00:29:10.840000+00:00        0.025921        0.997775   \n",
      "1970-01-02 00:29:10.850000+00:00        0.026011        0.997778   \n",
      "1970-01-02 00:29:10.860000+00:00        0.025339        0.997830   \n",
      "1970-01-02 00:29:10.870000+00:00        0.025130        0.997882   \n",
      "1970-01-02 00:29:10.880000+00:00        0.025071        0.997894   \n",
      "1970-01-02 00:29:10.890000+00:00        0.024700        0.997966   \n",
      "1970-01-02 00:29:10.900000+00:00        0.024264        0.997997   \n",
      "1970-01-02 00:29:10.910000+00:00        0.025038        0.997985   \n",
      "1970-01-02 00:29:10.920000+00:00        0.025402        0.997999   \n",
      "1970-01-02 00:29:10.930000+00:00        0.025568        0.998032   \n",
      "1970-01-02 00:29:10.940000+00:00        0.025339        0.998015   \n",
      "1970-01-02 00:29:10.950000+00:00        0.024511        0.998045   \n",
      "1970-01-02 00:29:10.960000+00:00        0.024088        0.998090   \n",
      "\n",
      "                                  eye_center1_3d_x  eye_center1_3d_y  \\\n",
      "gaze_timestamp                                                         \n",
      "1970-01-02 00:29:10.770000+00:00               NaN               NaN   \n",
      "1970-01-02 00:29:10.780000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.790000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.800000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.810000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.820000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.830000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.840000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.850000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.860000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.870000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.880000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.890000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.900000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.910000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.920000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.930000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.940000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.950000+00:00        -39.934928         14.997919   \n",
      "1970-01-02 00:29:10.960000+00:00        -39.934928         14.997919   \n",
      "\n",
      "                                  eye_center1_3d_z  gaze_normal1_x  \\\n",
      "gaze_timestamp                                                       \n",
      "1970-01-02 00:29:10.770000+00:00               NaN             NaN   \n",
      "1970-01-02 00:29:10.780000+00:00        -20.075283       -0.145087   \n",
      "1970-01-02 00:29:10.790000+00:00        -20.075283       -0.150232   \n",
      "1970-01-02 00:29:10.800000+00:00        -20.075283       -0.152198   \n",
      "1970-01-02 00:29:10.810000+00:00        -20.075283       -0.151952   \n",
      "1970-01-02 00:29:10.820000+00:00        -20.075283       -0.150413   \n",
      "1970-01-02 00:29:10.830000+00:00        -20.075283       -0.151138   \n",
      "1970-01-02 00:29:10.840000+00:00        -20.075283       -0.150791   \n",
      "1970-01-02 00:29:10.850000+00:00        -20.075283       -0.149916   \n",
      "1970-01-02 00:29:10.860000+00:00        -20.075283       -0.149606   \n",
      "1970-01-02 00:29:10.870000+00:00        -20.075283       -0.150185   \n",
      "1970-01-02 00:29:10.880000+00:00        -20.075283       -0.149704   \n",
      "1970-01-02 00:29:10.890000+00:00        -20.075283       -0.149820   \n",
      "1970-01-02 00:29:10.900000+00:00        -20.075283       -0.149847   \n",
      "1970-01-02 00:29:10.910000+00:00        -20.075283       -0.149284   \n",
      "1970-01-02 00:29:10.920000+00:00        -20.075283       -0.148602   \n",
      "1970-01-02 00:29:10.930000+00:00        -20.075283       -0.148867   \n",
      "1970-01-02 00:29:10.940000+00:00        -20.075283       -0.148678   \n",
      "1970-01-02 00:29:10.950000+00:00        -20.075283       -0.148821   \n",
      "1970-01-02 00:29:10.960000+00:00        -20.075283       -0.148850   \n",
      "\n",
      "                                  gaze_normal1_y  gaze_normal1_z  \n",
      "gaze_timestamp                                                    \n",
      "1970-01-02 00:29:10.770000+00:00             NaN             NaN  \n",
      "1970-01-02 00:29:10.780000+00:00        0.230744        0.962137  \n",
      "1970-01-02 00:29:10.790000+00:00        0.224797        0.962738  \n",
      "1970-01-02 00:29:10.800000+00:00        0.229156        0.961410  \n",
      "1970-01-02 00:29:10.810000+00:00        0.234021        0.960284  \n",
      "1970-01-02 00:29:10.820000+00:00        0.234215        0.960478  \n",
      "1970-01-02 00:29:10.830000+00:00        0.233532        0.960531  \n",
      "1970-01-02 00:29:10.840000+00:00        0.233569        0.960577  \n",
      "1970-01-02 00:29:10.850000+00:00        0.233780        0.960662  \n",
      "1970-01-02 00:29:10.860000+00:00        0.233583        0.960758  \n",
      "1970-01-02 00:29:10.870000+00:00        0.233384        0.960716  \n",
      "1970-01-02 00:29:10.880000+00:00        0.233300        0.960812  \n",
      "1970-01-02 00:29:10.890000+00:00        0.233547        0.960734  \n",
      "1970-01-02 00:29:10.900000+00:00        0.233968        0.960627  \n",
      "1970-01-02 00:29:10.910000+00:00        0.234162        0.960668  \n",
      "1970-01-02 00:29:10.920000+00:00        0.234394        0.960717  \n",
      "1970-01-02 00:29:10.930000+00:00        0.234479        0.960655  \n",
      "1970-01-02 00:29:10.940000+00:00        0.234164        0.960761  \n",
      "1970-01-02 00:29:10.950000+00:00        0.234277        0.960712  \n",
      "1970-01-02 00:29:10.960000+00:00        0.234256        0.960712  \n"
     ]
    }
   ],
   "source": [
    "# ex5\n",
    "import pandas as pd\n",
    "\n",
    "data2 = pd.read_csv('D:\\\\xzr\\\\pycharm\\\\数据科学编程\\\\gaze.csv')\n",
    "data2[\"gaze_timestamp\"] = pd.to_datetime(data2[\"gaze_timestamp\"].values, unit=\"s\", utc=True)\n",
    "data2 = data2.resample(\"0.01S\", on=\"gaze_timestamp\").mean()\n",
    "print(data2.head(20))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
